//
//  FourProsCell.m
//  project_delicious
//
//  Created by 章历杰 on 15/3/26.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "FourProsCell.h"
#import "UIImageView+AFNetworking.h"
#import "OneOfShopsViewController.h"
@implementation FourProsCell
- (void)dealloc
{
    [_mDic release];

    [_name release];
    [_pic release];
    [_details release];
    [_loca release];
    
    
    [_shopID release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.mDic = [NSMutableDictionary dictionary];
        
        self.name = [[UILabel alloc] init];
        [self.contentView addSubview:_name];
        [_name release];
        self.pic = [[UIImageView alloc] init];
        [self.contentView addSubview:_pic];
        [_pic release];
        self.details = [[UITextView alloc] init];
        [self.contentView addSubview:_details];
        [_details release];
        self.loca = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.contentView addSubview:_loca];
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    //菜名
    self.name.frame = CGRectMake(5, 5, self.contentView.frame.size.width-10, 20);
    //菜图
    self.pic.frame = CGRectMake(5, 28, self.contentView.frame.size.width-10, 200);
    //菜细节
    self.details.frame = CGRectMake(5, _pic.frame.origin.y+_pic.frame.size.height+3, self.contentView.frame.size.width-10, 70);
    //店
    self.loca.frame = CGRectMake(5, _details.frame.origin.y+_details.frame.size.height+3, self.contentView.frame.size.width-10, 20);
    
}
- (void)setMDic:(NSMutableDictionary *)mDic
{
    if (_mDic != mDic) {
        [_mDic release];
        _mDic = [mDic retain];
    }
    //名
    self.name.text = [self.mDic objectForKey:@"dish_name"];
    //图
    NSString *str = [self.mDic objectForKey:@"url"];
    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:str];
    [self.pic setImageWithURL:url];
    self.pic.layer.cornerRadius = 10;
    self.pic.layer.masksToBounds = YES;
    //介绍
    self.details.text = [self.mDic objectForKey:@"desc"];
    self.details.font = [UIFont systemFontOfSize:13];
    self.details.editable = NO;
    self.details.scrollEnabled = NO;
    self.details.backgroundColor = [UIColor clearColor];
    //店
    NSString *string = [self.mDic objectForKey:@"shop_names"];
    if (string != nil) {
        NSArray *arr1 = [string componentsSeparatedByString:@";"];
        NSMutableArray *arr = [NSMutableArray arrayWithArray:arr1];
        NSString *block = @"无";
        [arr addObject:block];
         //NSLog(@"%@",arr[0]);
        
        [self.loca setTitle: arr[1] forState:UIControlStateNormal];
        [self.loca addTarget:self action:@selector(click2) forControlEvents:UIControlEventTouchUpInside];
        self.shopID = arr[0];
        
    }
    
//    if (arr[0] != NULL) {
//        NSLog(@"%@",arr[1]);
//        [self.loca setTitle: arr[1] forState:UIControlStateNormal];
//        [self.loca addTarget:self action:@selector(click2) forControlEvents:UIControlEventTouchUpInside];
//    } else {
//        NSLog(@"%@", arr[0]);
//        [self.loca setTitle: arr[0] forState:UIControlStateNormal];
//        [self.loca addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
//    }
    
}

- (void)click2
{
    OneOfShopsViewController *one = [[OneOfShopsViewController alloc] init];
    one.num = self.shopID;
    [self.target pushViewController:one animated:NO];
    [one release];
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
